<template>
	<view class="content">
		<view class="ul">
			<view class="li" v-for="item in list" :key="item.id">
				<view class="order">{{item.desp}}</view>
				<view class="time">{{item.createdTime}}</view>
				<view class="money" v-if="item.inOrOut.value==1">+{{item.count}}</view>
				<view class="money" v-else>-{{item.count}}</view>
			</view>
			<view class="pagination" v-if="pagination">
				<view class="left" :class="{ forbid: paging.page == 1 }" @click="prev">
					<uni-icons type="arrowleft" size="20" color="#fff" class="icons" />
					上一页
				</view>
				<view class="center">{{ paging.page }}/{{ paging.total }}</view>
				<view class="right" :class="{ forbid: paging.page == paging.total }" @click="next">
					下一页
					<uni-icons type="arrowright" size="20" color="#fff" class="icons" />
				</view>
			</view>
			<view v-if="list.length==0" class="notavailable">
				<image src="../../../static/img/notavailable.png" mode="widthFix"></image>
				<view class="nottext">暂时没有数据</view>
			</view>
		</view>
	</view>
</template>

<script>
	import integral from '../../../servers/integral/integral.js';
	export default {
		data() {
			return {
				list:[],
				pagination:true,
				paging: {
					page: 1,
					total: 100
				},
			}
		},
		onLoad() {

		},
		mounted() {
			this.initData();
		},
		methods: {
			initData(){
				integral.mypoints()
					.then(res => {
						if(res.code==200){
							if(res.data.records.length>0){
								this.paging.total = Math.ceil(res.data.total / res.data.size);
								this.list = res.data.records;
								this.pagination=true
							}else{
								this.pagination=false
							}
							
							
						}else{
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
						}
						
					})
					.catch(err => {
						
						console.log(new Error('请检查网络后重试'));
					});
			},
			next() {
				if (this.paging.page < this.paging.total) {
					this.paging.page += 1;
					this.initData();
				}
			},
			prev() {
				if (this.paging.page > 1) {
					this.paging.page -= 1;
					this.initData();
				}
			}
		}
	}
</script>

<style scoped lang="scss" rel="stylesheet/scss">
	.ul {
		background: #ffffff;
		padding: 0rpx 20rpx;
		.li {
			position: relative;
			padding: 30rpx 0;
			border-bottom: 1px solid #e1e1e1;
			.order {
				font-size: 30rpx;
				margin-bottom: 10rpx;
			}
			.time {
				font-size: 26rpx;
				color: #999999;
			}
			.money {
				position: absolute;
				right: 0;
				top: 60rpx;
				font-size: 36rpx;
				color: #f70225;
			}
		}
		.li:nth-last-child(1) {
			border-bottom: none;
		}
	}
</style>
